/*
 * RoboEye - Web client for www.newocr.com that allows you
 * to recognize an image captured by the camera.
 *
 * Copyright (C) Oxygen Development, 2011
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.devoxy.roboeye.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.devoxy.roboeye.R;
import com.devoxy.roboeye.global.UiHelper;
import com.devoxy.roboeye.ui.activity.main.RoboEyeActivity;

/**
 * Created by Oxygen Development.
 * Author: Dmitriy Tarasov (dm.vl.tarasov@gmail.com)
 * Date: 04.05.11
 * Time: 1:11
 */
public class AboutActivity extends RoboEyeActivity {

    private static final String VERSION_PATTERN = "\\d\\.\\d\\.\\d";

    private TextView createdBy;
    private TextView userManual;
    private TextView licenseAgreement;
    private TextView projectHomePage;
    private TextView market;
    private TextView rateApp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);
        initProperties(savedInstanceState);
        initBehavior(savedInstanceState);
        initUI(savedInstanceState);
    }

    @Override
    public void initProperties(Bundle bundle) {
        createdBy = _findViewById(R.id.created_by);
        userManual = _findViewById(R.id.user_manual);
        licenseAgreement = _findViewById(R.id.license_agreement);
        projectHomePage = _findViewById(R.id.project_home_page);
        market = _findViewById(R.id.market);
        rateApp = _findViewById(R.id.rate_app);
    }

    @Override
    public void initBehavior(Bundle bundle) {
        findViewById(R.id.actionbar_home).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    @Override
    public void initUI(Bundle bundle) {
        UiHelper.addLink(this, R.id.app_version, VERSION_PATTERN, R.string.http_scheme, R.string.changelog_url);

        replaceAndLinkify(createdBy, R.string.created_by, R.string.my_name, R.string.email_scheme, R.string.my_email);
        replaceAndLinkify(userManual, R.string.user_manual, R.string.page, R.string.http_scheme, R.string.user_manual_url);
        replaceAndLinkify(licenseAgreement, R.string.license_agreement, R.string.license_type, R.string.http_scheme, R.string.license_agreement_url);
        replaceAndLinkify(projectHomePage, R.string.home_page, R.string.here, R.string.http_scheme, R.string.project_home_page_url);
        replaceAndLinkify(market, R.string.my_apps_in_market, R.string.market, R.string.market_scheme, R.string.market_url);
        replaceAndLinkify(rateApp, R.string.rate_app, R.string.rate_app, R.string.market_scheme, R.string.rate_app_url);
    }

    private void replaceAndLinkify(TextView tv, int srcId, int dstId, int schemeId, int linkId) {
        tv.setText(String.format(getString(srcId), getString(dstId)));
        UiHelper.addLink(this, tv.getId(), getString(dstId), schemeId, linkId);
    }

}